package main

import (
	stdContext "context"
	"flag"
	"github.com/kataras/iris/v12"
	"time"
	"wit-admin-go/conf"
	_ "wit-admin-go/docs"
	"wit-admin-go/system/boot"
)

// @title           Swagger wit-admin-go API
// @version         1.0
// @description     This is a sample server celler server.
// @contact.name   taiping
// @contact.email  954819510@qq.com
// @host      localhost:9999
// @BasePath  /wit
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
func main() {
	flag.Parse()
	sysConfig := iris.WithConfiguration(iris.YAML(conf.ConfigFile))
	app := boot.WitApp()
	idleConsClosed := make(chan struct{})
	iris.RegisterOnInterrupt(func() {
		timeout := 10 * time.Second
		ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
		defer cancel()
		// close all hosts.
		_ = app.Shutdown(ctx)
		close(idleConsClosed)
	})
	println("swagger url: http://127.0.0.1:" + conf.CONFIG.WitAdmin.Port + "/wit/index.html")
	err := app.Run(
		iris.Addr(conf.CONFIG.WitAdmin.Addr+":"+conf.CONFIG.WitAdmin.Port),
		sysConfig,
		iris.WithoutServerError(iris.ErrServerClosed), iris.WithSocketSharding)
	if err != nil {
		panic(err)
	}
	<-idleConsClosed
}
